package org.jeecg;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author jiguansheng
 * @date 2021/2/9
 **/
public class QuickExecuteRunnable implements Callable {


    private AtomicBoolean isDone;



    public String business ;
    private Object result ;

    public QuickExecuteRunnable(String business,  AtomicBoolean isDone,Object result) {
        this.business = business;
        this.isDone = isDone;
        this.result = result;

    }

    /**
     * Computes a result, or throws an exception if unable to do so.
     *
     * @return computed result
     * @throws Exception if unable to compute a result
     */
    @Override
    public Object call() throws Exception {
            doSomething();
        return business;
    }


    Random random = new Random();

    private void doSomething() throws InterruptedException {
        int sleepTime = random.nextInt(10);

        System.out.printf("execute busi:%s .... sleep: %s\n",business,sleepTime);
        TimeUnit.SECONDS.sleep(sleepTime);
        System.out.printf("busi:%s isDone \n",business);
        result = business;

        isDone.set(true);
    }
}
